/********************************************
 * 
 * 타이틀 : 메뉴 선택 화면
 * 기능 : 
 * 작성자 : LJI
 * 작성일 : 2013.09.26
 * 
 ********************************************/

package com.game.pacman.client;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class MenuScreen extends JPanel implements ActionListener{
	private Image imageBack; 
	private Client client;
	private String player;
	private PlayScreen screen;
	
	public MenuScreen(Image image,Client client,PlayScreen screen) {
//	public MenuScreen(Image image,Client client) {
		this.imageBack = image;
		this.client=client;
		this.screen=screen;
		init();
		
	}
	
	public void init(){
		setLayout(null);
		setBackground(Color.white);
		setBounds(0,0,Constants.WINDOW_WIDTH,Constants.WINDOW_HEIGHT);
		
		//종료
		JButton buttonExit=new JButton();
		
		buttonExit.setBounds(
				(Constants.WINDOW_WIDTH-Constants.BUTTON_WIDTH)/2,
				Constants.MAP_HEIGHT-Constants.BUTTON_HEIGHT-Constants.gap,
				Constants.BUTTON_WIDTH,
				Constants.BUTTON_HEIGHT);
		
		buttonExit.setText("종료");
		buttonExit.addActionListener(this);
		add(buttonExit);
		
		//순위보기
		JButton buttonRank=new JButton();
		
		buttonRank.setBounds(
				(Constants.WINDOW_WIDTH-Constants.BUTTON_WIDTH)/2,
				buttonExit.getY()-Constants.BUTTON_HEIGHT-Constants.gap,
				Constants.BUTTON_WIDTH,
				Constants.BUTTON_HEIGHT);
		
		buttonRank.setText("순위보기");
		buttonRank.addActionListener(this);
		add(buttonRank);

		//크래딧
		JButton buttonCredit=new JButton();
		
		buttonCredit.setBounds(
			(Constants.WINDOW_WIDTH-Constants.BUTTON_WIDTH)/2,
			buttonRank.getY()-Constants.BUTTON_HEIGHT-Constants.gap,
			Constants.BUTTON_WIDTH,
			Constants.BUTTON_HEIGHT);
		
		buttonCredit.setText("크래딧");
		buttonCredit.addActionListener(this);
		add(buttonCredit);
		
		//시작하기
		JButton buttonStart=new JButton();
		
		buttonStart.setBounds(
			(Constants.WINDOW_WIDTH-Constants.BUTTON_WIDTH)/2,
			buttonCredit.getY()-Constants.BUTTON_HEIGHT-Constants.gap,
			Constants.BUTTON_WIDTH,
			Constants.BUTTON_HEIGHT);
		
		buttonStart.setText("시작하기");
		buttonStart.addActionListener(this);
		add(buttonStart);
	}
	
	//메뉴 버튼을 눌렀을 때 동작
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() instanceof JButton){
			String strMenu = ((JButton)e.getSource()).getText();
			switch(strMenu){
				case "시작하기":
					//player = JOptionPane.showInputDialog( "이름을 입력하세요." );
					try{
						//client.sendData(player);
					}catch(NullPointerException ne){
					}finally{
						GameFrame.card.show(GameFrame.mainScreen,Constants.PLAY_SCREEN);
						screen.startGame();
						break;
					}					
				case "크래딧":
					GameFrame.card.show(GameFrame.mainScreen, Constants.CREDIT_SCREEN);
					break;
				case "순위보기":
					GameFrame.card.show(GameFrame.mainScreen, Constants.RANK_SCREEN);
					break;
				case "종료":
					try{
						//client.sendData("stop");
					}catch(NullPointerException ne){
						System.exit(0);
					}finally{
						//client.stopClient(); //통신종료
						System.exit(0);
						break;
					}
				default:
			}	
		}
	}
	
	//배경이미지 표시
	@Override
	public void paint(Graphics g) {
		g.drawImage(imageBack,0, 0,null);
		setOpaque(false);
		super.paint(g);
	}

}
